package cn.legend.travel.admin.content.service.impl;

import cn.legend.travel.admin.content.dao.persist.repository.IReviewRepository;
import cn.legend.travel.admin.content.pojo.vo.ReviewCheckVO;
import cn.legend.travel.admin.content.pojo.vo.ReviewDetailVO;
import cn.legend.travel.admin.content.service.IReviewService;
import cn.legend.travel.common.enumerator.ServiceCode;
import cn.legend.travel.common.exception.ServiceException;
import cn.legend.travel.common.pojo.vo.PageData;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ReviewServiceImpl implements IReviewService {
    private final IReviewRepository reviewRepository;
    @Value("${travel.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;

    @Override
    public PageData<ReviewCheckVO> list(Integer pageNum) {
        return reviewRepository.list(pageNum,defaultQueryPageSize);
    }

    @Override
    public void check(Long id, Integer state) {
        int row = reviewRepository.check(id,state);
        if (row != 1) {
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"服务器忙,请稍后再试");
        }
    }

    @Override
    public void changeDisplay(Long id, Integer isDisplay) {
        int row = reviewRepository.changeDisplay(id,isDisplay);
        if (row != 1) {
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"服务器忙,请稍后再试");
        }
    }

    @Override
    public ReviewDetailVO getDetail(Long id) {
        return reviewRepository.getDetail(id);
    }
}
